// --------------------------------------------------------------------------------------------------------------------
// <copyright file="IStrategyModelCell.cs" company="Open Trader">
//   Copyright (c) David Denis (david.denis@systemathics.com)
// </copyright>
// <summary>
//   |  Open Trader - The Open Source Systematic Trading Platform
//   |
//   |  This program is free software: you can redistribute it and/or modify
//   |  it under the terms of the GNU General Public License as published by
//   |  the Free Software Foundation, either version 2 of the License, or
//   |  (at your option) any later version.
//   |
//   |  This program is distributed in the hope that it will be useful,
//   |  but WITHOUT ANY WARRANTY; without even the implied warranty of
//   |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   |  GNU General Public License for more details.
//   |
//   |  You should have received a copy of the GNU General Public License
//   |  along with this program.  If not, see http://www.gnu.org/licenses
//   |
//   |  Up to date informations about Open Trader can be found at :
//   |    http://opentrader.org
//   |    http://opentrader.codeplex.com
//   |
//   |  For professional services, please visit us at :
//   |    http://www.systemathics.com
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Org.OpenTrader.Framework.Forge.Interfaces
{
    #region Using Directives

    using System;

    using Org.OpenTrader.Framework.Forge.Events;

    #endregion

    /// <summary>
    /// The e strategy status.
    /// </summary>
    [Serializable]
    public enum EStrategyStatus
    {
        /// <summary>
        /// The starting.
        /// </summary>
        Starting = 10, 

        /// <summary>
        /// The started.
        /// </summary>
        Started = 11, 

        /// <summary>
        /// The stopping.
        /// </summary>
        Stopping = 20, 

        /// <summary>
        /// The stopped.
        /// </summary>
        Stopped = 21
    }

    /// <summary>
    /// The e strategy time frame type.
    /// </summary>
    [Serializable]
    public enum EStrategyTimeFrameType
    {
        /// <summary>
        /// The low frequency.
        /// </summary>
        LowFrequency = 10, 

        /// <summary>
        /// The medium frequency.
        /// </summary>
        MediumFrequency = 11, 

        /// <summary>
        /// The high frequency.
        /// </summary>
        HighFrequency = 20, 
    }

    /// <summary>
    /// The e instrument status.
    /// </summary>
    [Serializable]
    public enum EInstrumentStatus
    {
        /// <summary>
        /// The enabled.
        /// </summary>
        Enabled = 1, 

        /// <summary>
        /// The buy enabled.
        /// </summary>
        BuyEnabled = 2, 

        /// <summary>
        /// The sell enabled.
        /// </summary>
        SellEnabled = 3, 

        /// <summary>
        /// The restricted.
        /// </summary>
        Restricted = 4, 

        /// <summary>
        /// The short sell enabled.
        /// </summary>
        ShortSellEnabled = 5, 

        /// <summary>
        /// The black listed.
        /// </summary>
        BlackListed = 6, 

        /// <summary>
        /// The hard to borrow.
        /// </summary>
        HardToBorrow = 7
    }

    /// <summary>
    /// The i strategy sector.
    /// </summary>
    public interface IStrategyModelCell
    {
        #region Properties

        /// <summary>
        /// Config Table
        /// </summary>
        Table Config { get; }

        /// <summary>
        /// Market Expo
        /// </summary>
        StrategyExpo Expo { get; }

        /// <summary>
        /// Sector Name
        /// </summary>
        string Name { get; }

        /// <summary>
        /// Strategy model of this cell
        /// </summary>
        IStrategyModel Parent { get; }

        /// <summary>
        /// Start time
        /// </summary>
        TimeSpan StartAt { get; }

        /// <summary>
        /// Status
        /// </summary>
        EStrategyStatus Status { get; }

        /// <summary>
        /// Stop time
        /// </summary>
        TimeSpan StopAt { get; }

        /// <summary>
        /// Number of parameters
        /// </summary>
        int NbParams { get; }

        #endregion

        #region Indexers

        /// <summary>
        /// Get the instrument using index
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        IInstrument this[int index]
        {
            get;
        }

        /// <summary>
        /// Get the instrument using index
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        IInstrument this[string code]
        {
            get;
        }

        /// <summary>
        /// Get the instrument using Guid
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        IInstrument this[Guid id]
        {
            get;
        }
        
        #endregion

        #region Public Methods

        /// <summary>
        /// Add the instrument i to the cell
        /// </summary>
        /// <param name="i">
        /// </param>
        /// <returns>
        /// The add.
        /// </returns>
        bool Add(IInstrument i);

        /// <summary>
        /// Add the instrument to the cell
        /// </summary>
        /// <param name="code">
        /// Code of the instrument : not empty
        /// </param>
        /// <returns>
        /// The add.
        /// </returns>
        bool Add(string code);

        /// <summary>
        /// Remove Instrument
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        bool Remove(IInstrument i);

        /// <summary>
        /// Remove Instrument
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        bool Remove(string code);

        /// <summary>
        /// Remove Instrument
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        bool Remove(Guid id);
        
        /// <summary>
        /// Cancel Buy orders of this cell
        /// </summary>
        /// <returns>
        /// The cancel buy orders.
        /// </returns>
        int CancelBuyOrders();

        /// <summary>
        /// Cancel all orders of this cell
        /// </summary>
        /// <returns>
        /// The cancel orders.
        /// </returns>
        int CancelOrders();

        /// <summary>
        /// Cancel Sell orders of this cell
        /// </summary>
        /// <returns>
        /// The cancel sell orders.
        /// </returns>
        int CancelSellOrders();

        /// <summary>
        /// Check starting parameters before starting this cell
        /// </summary>
        /// <param name="time">
        /// The time.
        /// </param>
        /// <returns>
        /// The check starting.
        /// </returns>
        bool CheckStarting(TimeSpan time);

        /// <summary>
        /// Number of instrument in this basket where status
        /// </summary>
        /// <param name="status">
        /// The status.
        /// </param>
        /// <returns>
        /// The nb.
        /// </returns>
        int Nb(EInstrumentStatus status);

        /// <summary>
        /// OnFeed event
        /// </summary>
        /// <param name="sender">
        /// </param>
        /// <param name="args">
        /// </param>
        void OnFeed(object sender, FeedEventArgs args);

        /// <summary>
        /// OnOrder reply
        /// </summary>
        /// <param name="sender">
        /// </param>
        /// <param name="args">
        /// </param>
        void OnOrder(object sender, OrderTrackingEventArgs args);

        /// <summary>
        /// Synchronous Timer call (BackgroundWorker)
        /// </summary>
        void Run();

        /// <summary>
        /// The set param.
        /// </summary>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <param name="val">
        /// The val.
        /// </param>
        /// <returns>
        /// The set param.
        /// </returns>
        bool SetParam(string key, Table.Cell val);

        /// <summary>
        /// The start.
        /// </summary>
        /// <returns>
        /// The start.
        /// </returns>
        bool Start();

        /// <summary>
        /// The stop.
        /// </summary>
        /// <returns>
        /// The stop.
        /// </returns>
        bool Stop();

        #endregion
    }
}